/**
 * 处理sql请求
 */
const db = require('./index');
function reqSqlData(sql, data) {
  console.log(sql)
  return new Promise((resolve, reject) => {
    db.query(sql ,data ,(err, results) => {

      console.log('typeof results', typeof results)
      if (err) return reject(err);
      if (typeof results == 'array') {
        if (results > 0) {
          return resolve(results)
        } else {
          return reject(err)
        }
      } else if (typeof results == 'object') {
        if (results.affectedRows !== 1) {
          return reject(err)
        } else {
          return resolve(results.affectedRows)
        }
      }
    })
  })

}

module.exports = reqSqlData